package listener;

import javax.servlet.*;

public class ApplicationListener implements ServletContextListener, ServletContextAttributeListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("contextInitialized");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("contextDestroyed");
    }

    @Override
    public void attributeAdded(ServletContextAttributeEvent scae) {
        System.out.println("ServletContextAttributeAdded:"+scae.getName()+" "+scae.getValue());
    }

    @Override
    public void attributeRemoved(ServletContextAttributeEvent scae) {
        System.out.println("ServletContextAttributeRemoved:"+scae.getName()+" "+scae.getValue());
    }

    @Override
    public void attributeReplaced(ServletContextAttributeEvent scae) {
        // 旧值  新值
        ServletContext servletContext = scae.getServletContext();
        System.out.println("ServletContextAttributeReplaced:"+scae.getName()+" "+scae.getValue()+" 新值："+servletContext.getAttribute(scae.getName()));
    }
}
